// /utils/bluetooth/bluetooth.harmony.ts
class HarmonyBluetoothManager {
	private plugin : any = null

	constructor() {
		try {
			this.plugin = uni.requireNativePlugin('harmony-bluetooth_1')
			console.log('✅ 启用鸿蒙蓝牙插件')
		} catch (e) {
			console.error('❌ 加载鸿蒙蓝牙插件失败', e)
		}
	}

	openBluetooth() {
		console.log('11111');
		this.plugin?.openBluetoothAdapter?.()
	}

	startDiscovery() {
		this.plugin?.startScan?.()
	}

	stopDiscovery() {
		this.plugin?.stopScan?.()
	}

	connectDevice(device : { deviceId : string }) {
		this.plugin?.connect?.(device.deviceId)
	}

	disconnectDevice(deviceId : string) {
		this.plugin?.disconnect?.(deviceId)
	}
	
	getState() {
		this.plugin?.getBluetoothState?.()
	}

	isConnected() {
		return false
	}

	setDeviceAlias() { }

	getDeviceAlias() {
		return null
	}
}
/** 单例导出 */
let instance : HarmonyBluetoothManager | null = null
export function mc_initBluetooth() : HarmonyBluetoothManager {
	if (!instance) instance = new HarmonyBluetoothManager()
	return instance
}